﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace BreakOutBattles.Game.Items
{
    #region Enums
    public enum AnimationDirection
    {
        HORIZONTAL,
        VERTICAL
    }
    #endregion

    public class DancingBrick : Brick
    {
        #region Fields
        private AnimationDirection animationDirection;
        private int defaultResistance = 3;
        private int direction = -1;
        private int moveSpeed = 100;
        private int maxLeft;
        private int maxRight;
        private int maxTop;
        private int maxBottom;
        #endregion

        public DancingBrick(Vector2 location, Texture2D itemTexture, AnimationDirection animationDirection = AnimationDirection.HORIZONTAL)
            : base(location, itemTexture)
        {
            this.animationDirection = animationDirection;
            destructionBonus = 50;
            Resistance = defaultResistance;
            maxLeft = CollisionRect.Left - CollisionRect.Width * 2;
            maxRight = CollisionRect.Right + CollisionRect.Width * 2;
            maxTop = CollisionRect.Top - CollisionRect.Height * 3;
            maxBottom = CollisionRect.Bottom + CollisionRect.Height * 2;
        }

        /// <summary>
        /// Resets the brick to its default behaivour.
        /// </summary>
        public override void Reset()
        {
            base.Reset();
            Resistance = defaultResistance;
            currentLocation = initialLocation;
            direction = -1;
        }

        /// <summary>
        /// Moves the brick, vertically or horizontally, depending on the current animation setting.
        /// </summary>
        private void Animate(GameTime gameTime)
        {
            if ((currentLocation.X < maxLeft) || (currentLocation.Y < maxTop))
            {
                direction = 1;
            }
            else if ((currentLocation.X > maxRight) || (currentLocation.Y > maxBottom))
            {
                direction = -1;
            }

            if (animationDirection == AnimationDirection.HORIZONTAL)
            {
                currentLocation.X += direction * (moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds);
            }
            else if (animationDirection == AnimationDirection.VERTICAL)
            {
                currentLocation.Y += direction * (moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds);
            }
        }

        /// <summary>
        /// Gets a boolean indicating if the ball is on motion.
        /// </summary>
        public override bool OnMotion
        {
            get
            {
                return true;
            }
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            Animate(gameTime);
        }

    }
}
